﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using Convertor.Interface;
using Wpf.CommonTools.SystemExtension;

namespace Convertor
{
    class TemplateTypesConverter : IValueConverter
    {

        #region IValueConverter 成员

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var list = value as ObservableCollection<ITemplateToLoadViewModel>;
            if (list != null)
            {
                var names = new string[] { UILanguage.FindResource("Template_All").ToString(), UILanguage.FindResource("Template_NotGrouped").ToString() }
                    .Union(
                    list.Where(p => p.Name.Split('-').Length > 1).Select(p => p.Name.Split('-')[0]).GroupBy(p => p).Select(p => p.Key));
                return names;
            }
            else
            {
                return new string[] { UILanguage.TryFindResource("Template_All") };
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
